//
//  ChangeUserNameController.m
//  tryshopping.boss
//
//  Created by Mr.Lee on 16/12/6.
//  Copyright © 2016年 Reabam. All rights reserved.
//

#import "ChangeUserNameController.h"

@interface ChangeUserNameController ()
//输入框
@property (weak, nonatomic) IBOutlet UITextField *nameTF;
// 输入框下面的线
@property (weak, nonatomic) IBOutlet UIImageView *img;
// 确定按钮
@property (weak, nonatomic) IBOutlet UIButton *configBtn;

@end

@implementation ChangeUserNameController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"更改昵称";
    self.configBtn.layer.cornerRadius = 4.0;
    self.configBtn.layer.masksToBounds = YES;
    self.configBtn.backgroundColor = CommonColor;

//    [self.nameTF addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
}

- (void)textFieldDidChange:(UITextField *)tf{
//    DLog(@"%@", tf.text);
}


//- (void)viewWillAppear:(BOOL)animated{
//    [super viewWillAppear:animated];
//
//
//    [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
////    [self.navigationController setNavigationBarHidden:NO animated:YES];
//
//}
//
//- (void)viewWillDisappear:(BOOL)animated{
//    [super viewWillDisappear:animated];
////    [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
//}



- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
}


// 点击确定
- (IBAction)configBtnClick:(UIButton *)sender {
    
    if (self.nameTF.text.length > 0) {
        
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        NSString* Token = [user objectForKey:@"tokenId"];
        NSMutableDictionary *params = [NSMutableDictionary new];
        [params setValue:Token forKey:@"tokenId"];
        [params setValue:self.nameTF.text forKey:@"userName"];
//        DLog(@"33333333====%@",params);
        [HttpRequest requestData1:@"Common/UpdateUser" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                
//                DLog(@"====%@",severDataDict.dataDict);
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [MBProgressHUD hideProgressHUDInternal:self.view];
                    [MBProgressHUD showTextHudSub:@"修改成功" view:self.view];
                    [[NSNotificationCenter defaultCenter] postNotificationName:@"upDataUserInfo" object:nil];
//                    [[NSUserDefaults standardUserDefaults] setObject:@"userName" forKey:self.nameTF.text];
//                    [[NSUserDefaults standardUserDefaults] synchronize];
                    
                    
                }else{
                    
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];

                    [MBProgressHUD showTextHud:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {

                        LoginViewController* Login=[[LoginViewController alloc]init];
                        [self.navigationController pushViewController:Login animated:YES];

                    }
                }
            } else {
                [MBProgressHUD hideProgressHUDInternal:self.view];
                [MBProgressHUD showTextHudSub:severDataDict.resultStr view:self.view];
            }
            
        }];
    }
}


@end
